﻿package framework.core;

import java.util.*;

/**
 * Creation date: (2003-08-28)
 * @author: adminnistrator
 * 处理器管理类
 * Debug.ON=false时提供高速缓存功能
 */
 
public class HandlerManager 
{
	//操作处理类
	private static HashMap m_classes = new HashMap();

	//action handler 映射
	private static HashMap m_action_handlers = new HashMap();

public HandlerManager() {
	super();
}
	private static void clear()
	{
		m_classes.clear();
		m_action_handlers.clear();
	}
private static IHandler getClass(String class_name) throws Exception
{
	if(m_classes.containsKey(class_name))
	{
		return (IHandler)m_classes.get(class_name);
	}
	IHandler cls = (IHandler)Class.forName(class_name).newInstance();
	m_classes.put(class_name,cls);
	return cls;
}
public static IHandler getHandler(DBConnection con,String action_type) throws Exception
{
	if(Config.isDebug())
	{
		clear();
	}
	//hit cache
	if(m_action_handlers.containsKey(action_type))
	{
		return (IHandler)m_action_handlers.get(action_type);
	}
	ActionHandler action_handler = ActionHandler.fetch(con,action_type);
	if(null==action_handler) return null;

	IHandler handler = getClass(action_handler.getClassName());
	m_action_handlers.put(action_type,handler);
	return handler;
}
}
